import QtQuick
import QtQuick.Controls
import QtQuick.Window

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Dial与键盘事件")

    Dial {
        id: control
        anchors.centerIn: parent
        width: 200
        height: 200
        from: 0
        to: 100
        stepSize: 1
        value: 50

        // 启用键盘焦点
        focus: true

        // 键盘事件处理
        Keys.onPressed: {
            const step = event.modifiers & Qt.ShiftModifier ? 10 : 1
            switch(event.key) {
            case Qt.Key_Up:
            case Qt.Key_Right:
                control.value = Math.min(control.value + step, control.to)
                break
            case Qt.Key_Down:
            case Qt.Key_Left:
                control.value = Math.max(control.value - step, control.from)
                break
            case Qt.Key_Home:
                control.value = control.from
                break
            case Qt.Key_End:
                control.value = control.to
                break
            }
        }

        // 添加焦点可视化
        background: Rectangle {
            border.color: control.activeFocus ? "blue" : "transparent"
            border.width: 2
            radius: width / 2
        }
    }
}
